//import {makeObservable,observable,action, computed}  from 'mobx';
import {makeAutoObservable,autorun, reaction, values, runInAction} from 'mobx';
import {configure} from 'mobx';
configure({
  enforceActions:'never'
})
class Counter{
  constructor(){
    // makeObservable(this,{
    //   count:observable,
    //   increment:action,
    //   decrement:action.bound,
    //   double:computed
    // })
    makeAutoObservable(this,{},{autoBind:true})
  }
  count=0;
  // increment(){
  //   setTimeout(() => {
  //     this.count++
  //   }, 1000);
  // }
  // increment(){
  //   this.count++
  // }
  incrementAsync(){
    setTimeout(this.increment,1000)
  }
  increment(){
    setTimeout(() => {
      runInAction(()=>{
        this.count++;
      })
    }, 1000);
  }
  decrement(){
    this.count--
  }
  reset(){
    this.count=0;
  }
  get double(){
    return this.count*2;
  }
}
const counter=new Counter()
// autorun(()=>{
//   console.log("----------"+counter.count);
// })
reaction(()=>counter.count,(newValue, oldValue)=>{
  console.log('counter.count变化了',newValue,oldValue);
})
export default counter